package operation_system.philosopher_eating;


class AEatAndThink implements Runnable {
    private Object lockL;
    private Object lockR;
    public AEatAndThink(Object lockL, Object lockR) {
        this.lockL = lockL;
        this.lockR = lockR;
    }



    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (lockL) {
                System.out.println("线程：" + Thread.currentThread().getName() + " 拿到了左边的筷子！");
                try {
                    //加快死锁出现
                    Thread.sleep(300);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (lockR) {
                    System.out.println("线程：" + Thread.currentThread().getName() + " 拿到了右边的筷子！");
                    System.out.println("线程：" + Thread.currentThread().getName() + " 开始吃饭！");
                    System.out.println("线程：" + Thread.currentThread().getName() + " 吃完了！");
                }
            }
        }
    }
}
